<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Events</title>
<link rel="stylesheet" type="text/css" href="css/Style.css" />
<link href='http://fonts.googleapis.com/css?family=Lily+Script+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Rock+Salt' rel='stylesheet' type='text/css'>


<%@ page import="java.util.ArrayList,es.ats.codington.festival.domain.Event" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
int isAdmin = 0;
String visitorName=null;
Cookie cookie= null;
Cookie[] cookies=request.getCookies();
if(cookies!=null){
	for(int i=0; i<cookies.length; i++){
		cookie=cookies[i];
		if(cookie.getName().compareTo("user")==0)
		visitorName=cookie.getValue();
		if(cookie.getName().compareTo("isAdmin")==0)
		isAdmin = Integer.parseInt(cookie.getValue());
	}
}
if(visitorName==null)response.sendRedirect("login.htm");
%>
<%ArrayList<Event> allEvents = (ArrayList<Event>) request.getAttribute("allEvents");%>
<%ArrayList<Event> registeredList = (ArrayList<Event>) request.getAttribute("registeredList");%>
<%ArrayList<Event> unregisteredList = (ArrayList<Event>) request.getAttribute("unregisteredList");%>
<c:set var="userName" value="<%= visitorName%>"></c:set>
<c:set var="isAdmin" value="<%= isAdmin%>"></c:set>

</head>
<body>

<header class="cabecera">

<div class="image">

	<img src="Images/Skyline.png" alt="My title image">

	
	<c:if test="${isAdmin==0}">
	<div class="login"> 
		<img src="Images/icon.png" alt="icono">
		<a href="infVisitor.htm"><%= visitorName %></a> / <a href="index.htm">LogOut</a>
	</div>
	</c:if>
	<c:if test="${isAdmin==1}">
	<div class="login"> 
 		<img src="Images/icon.png" alt="icono">
 		
 		<a href="infVisitor.htm">Welcome dear leader</a> / <a href="index.htm">LogOut</a>
	</div>
	</c:if>
	
	
</div>

<!-- Menu -->
<nav class="nav"> 
	<ul class="menu">
		<li><a href="index2.htm"> Home</a></li>
		<li><a href="#"> North Town</a>
			<ul>
				<li><a href="museum.htm"> Museum</a></li>
				<li><a href="theater.htm"> Theater</a></li>
				<li><a href="stadium.htm"> Stadium</a></li>
				<li><a href="business.htm"> Business</a></li>
			</ul>
		</li>
		<li><a href="#"> South Town</a>
			<ul>
				<li><a href="park.htm"> Park</a></li>
				<li><a href="zoo.htm"> Zoo</a></li>
				<li><a href="attractions.htm"> Attractions</a></li>
				<li><a href="markets.htm"> Markets</a></li>
			</ul>
		</li>
		<li><a href="show_events.htm"> Events</a></li>
	</ul>
 </nav>


</header>
<c:if test="${isAdmin==0}">
<div class="Container">
	<h2>Registered Events</h2>
	
	<table border="1">
		<tr >
			<th><label for="evName"> Event Name</label></th>
			<th><label for="evDescription"> Description</label></th>
			<th><label for="evDuration"> Duration</label></th>
			<th><label for="evType"> Event type</label></th>
			<th><label for="place"> Place</label></th>
			<th><label for="Unregister"> Unregister</label></th>
		</tr>
		<%for (int i=0; i<registeredList.size(); i++){ %>
		
		<tr >
		<form action="event_unsignup.htm" method="post">
		<input type="hidden" name="eventId" value=<%=registeredList.get(i).getEventId()%>>
			<td><%=registeredList.get(i).getEventName()%></td>
			<td><%=registeredList.get(i).getEventDescription()%></td>
			<td><%=registeredList.get(i).getDuration()%></td>
			<td><%=registeredList.get(i).getEventType()%></td>
			<td><%=registeredList.get(i).getPlaces().getPlaceName()%></td>
			<td> <input type="submit" name="Unregister" value="Unregister"/></td>
		</form>
		</tr>
		<%}%>
	</table>
</div>

<div class="Container">
	<h2>Events</h2>
	
	<table border="1">
		<tr >
			<th><label for="evName"> Event Name</label></th>
			<th><label for="evDescription"> Description</label></th>
			<th><label for="evDuration"> Duration</label></th>
			<th><label for="evType"> Event type</label></th>
			<th><label for="evTicket"> Ticket</label></th>
			<th><label for="place"> Place</label></th>
			<th><label for="Register"> Register</label></th>
		</tr>
		<%for (int i=0; i<unregisteredList.size(); i++){ %>
		
		<tr >
		<form action="event_signup.htm" method="post">
		<input type="hidden" name="eventId" value=<%=unregisteredList.get(i).getEventId()%>>
			<td><%=unregisteredList.get(i).getEventName()%></td>
			<td><%=unregisteredList.get(i).getEventDescription()%></td>
			<td><%=unregisteredList.get(i).getDuration()%></td>
			<td><%=unregisteredList.get(i).getEventType()%></td>
			<td><%=Integer.parseInt(unregisteredList.get(i).getTickets())-Integer.parseInt(unregisteredList.get(i).getUsTickets())%></td>
			<td><%=unregisteredList.get(i).getPlaces().getPlaceName()%></td>
			<c:set var="av" value="<%= Integer.parseInt(unregisteredList.get(i).getTickets())-Integer.parseInt(unregisteredList.get(i).getUsTickets())%>"></c:set>
			<c:if test="${av<=0}"><td>No Available</td> </c:if>
			<c:if test="${av>0}"><td> <input type="submit" name="Register" value="Register"/></td> </c:if>
		</form>
		</tr>
		<%}%>
	</table>
</div>
</c:if>

<c:if test="${isAdmin==1}">
<div class="Container">
	<h2>Events</h2>
	
	<table border="1">
		<tr >
			<th><label for="evName"> Event Name</label></th>
			<th><label for="evDescription"> Description</label></th>
			<th><label for="evDuration"> Duration</label></th>
			<th><label for="evType"> Event type</label></th>
			<th><label for="evTicket"> Ticket</label></th>
			<th><label for="place"> Place</label></th>
			<th><label for="Update"> Update</label></th>
			<th><label for="Delete"> Delete</label></th>
		</tr>
		<%for (int i=0; i<allEvents.size(); i++){ %>
		
		<tr >
		
			<td><%=allEvents.get(i).getEventName()%></td>
			<td><%=allEvents.get(i).getEventDescription()%></td>
			<td><%=allEvents.get(i).getDuration()%></td>
			<td><%=allEvents.get(i).getEventType()%></td>
			<td><%=allEvents.get(i).getTickets()%></td>
			<td><%=allEvents.get(i).getPlaces().getPlaceName()%></td>
			<form action="inf_event.htm" method="post">
			<input type="hidden" name="eventId" value=<%=allEvents.get(i).getEventId()%>>
			<td> <input type="submit" name="Update" value="Update"/></td>
			</form>
			<form action="delete_event.htm" method="post">
			<input type="hidden" name="eventId" value=<%=allEvents.get(i).getEventId()%>>
			<td> <input type="submit" name="Delete" value="Delete"/></td>
			</form>
		</tr>
		<%}%>
	</table>
	<!--new event page button -->
		<div class="button2">
			<a href="eventRegistration.htm" class="bu">New Event</a>
	</div>
</div>
		
</c:if>



<footer> Copyright @ 2015 All rights reserved </footer>
</body>
</html>